package cn.lcl.basic.dao.impl;

import cn.lcl.basic.dao.BaseDao;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.io.Serializable;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;

/**
 * Created by licho on 2017/8/9 0009.
 */
public abstract class AbstractBaseDao<T> implements BaseDao<T> {

    protected SessionFactory factory;//Hibernate的SessionFactory

    private Class<T> clazz;

    public AbstractBaseDao(){
        Type type=((ParameterizedType)this.getClass().getGenericSuperclass()).getActualTypeArguments()[0];
        this.clazz=(Class<T>)type;
    }
    @Override
    public boolean add(T vo) {
        Session session=factory.getCurrentSession();
        session.save(vo);
        return true;
    }

    @Override
    public boolean delete(T vo) {
        Session session=factory.getCurrentSession();
        session.delete(vo);
        return true;
    }

    @Override
    public boolean update(T vo) {
        Session session=factory.getCurrentSession();
        session.update(vo);
        return false;
    }

    @Override
    public T selectById(Serializable id) {
        Session session=factory.getCurrentSession();
        T result=session.get(this.clazz,id);
        return result;
    }

    @Override
    public List<T> selectListByPage() {
        Session session=factory.getCurrentSession();

        return null;
    }



}
